<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide
        v-for="(page,index) of pages"
        :key="index"
      >
        <div
          class="icon"
          v-for="item of page"
          :key="item.id"
        >
          <div class='icon-img'>
            <img
              class='icon-img-content'
              :src="item.imgUrl"
            />
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div
        class="swiper-pagination"
        slot="pagination"
      ></div>
    </swiper>
  </div>
</template>
<script>
export default {
  name: "HomeIcons",
  props: {
    list: Array
  },
  data() {
    return {
      swiperOption: {
        autoplay: false,
        pagination: ".swiper-pagination"
      }
    };
  },
  computed: {
    pages() {
      const pages = [];
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    }
  }
};
</script>
<style lang="stylus" scoped>
.icons >>> .swiper-pagination-bullet-active {
  background: rgba(0, 175, 190, 0.8);
}

.icons {
  margin-top: 0.1rem;
  overflow: hidden;
  height: 0;
  padding-bottom: 47%;
}

.icons .icon {
  float: left;
  width: 25%;
  padding-top: 0.2rem;
  text-align: center;
}

.icons .icon .icon-img>img {
  width: 1.1rem;
}

.icons .icon>.icon-desc {
  padding-top: 0.1rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>

